package com.lwg.datastructure.dynamicPrograming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @FileName: CanPartition.java
 * @Description: 分隔等和子集
 * @Date: 2022/2/15 0015
 */
public class CanPartition {
    public boolean canPartition(int[] nums) {
        int sum = 0;
        // 1.循环遍历得到数组sum总和
        for (int num : nums) {
            sum += num;
        }
        // 2.利用&1==1 判断总和sum是否是偶数
        if ((sum & 1) == 1) {
            return false;
        }
        // 3.得到数组的长度，用以遍历
        int length = nums.length;
        // 4.得到目标数
        int target = sum >> 1;

        /*// 5.创建二维数组
        int[][] dp = new int[length + 1][target + 1];
        dp[0][0] = 0;
        for (int i = 1; i <= length; i++) {
            for (int j = 1; j <= target; j++) {
                // 6.当前数字大于当前目标
                if (nums[i - 1] > j) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - nums[i - 1]] + nums[i - 1]);
                }
            }
        }*/

        //return dp[length][target] == target;
        //创建一维数组
        boolean[] dp = new boolean[target + 1];
        dp[0] = true;
        for (int i = 1; i <= length; i++) {
            for (int j = target; j >= 1; j--) {
                if (j > nums[i - 1]) {
                    dp[j] = (dp[j] || dp[j - nums[i - 1]]);
                }
            }
        }
        return dp[target];
    }
}

class MainClass {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for (int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static String booleanToString(boolean input) {
        return input ? "True" : "False";
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] nums = stringToIntegerArray(line);

            boolean ret = new CanPartition().canPartition(nums);

            String out = booleanToString(ret);

            System.out.print(out);
        }
    }
}